﻿using System;
using System.Data;
using System.Collections.Generic;
using Manager.Model.Admin;
namespace Manager.BLL.Admin
{
    /// <summary>
    /// M_Shop
    /// </summary>
    public partial class M_ShopBll
    {
        private readonly Manager.DAL.Admin.M_ShopDal dal = new Manager.DAL.Admin.M_ShopDal();
        public M_ShopBll()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ShopID)
        {
            return dal.Exists(ShopID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Manager.Model.Admin.M_Shop model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Manager.Model.Admin.M_Shop model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ShopID)
        {

            return dal.Delete(ShopID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string ShopIDlist)
        {
            return dal.DeleteList(ShopIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Manager.Model.Admin.M_Shop GetModel(int ShopID)
        {

            return dal.GetModel(ShopID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Manager.Model.Admin.M_Shop GetModelByCache(int ShopID)
        {

            string CacheKey = "M_ShopModel-" + ShopID;
            object objModel = Manager.Tools.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ShopID);
                    if (objModel != null)
                    {
                        int ModelCache = Manager.Tools.ConfigHelper.GetConfigInt("ModelCache");
                        Manager.Tools.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Manager.Model.Admin.M_Shop)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Manager.Model.Admin.M_Shop> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Manager.Model.Admin.M_Shop> DataTableToList(DataTable dt)
        {
            List<Manager.Model.Admin.M_Shop> modelList = new List<Manager.Model.Admin.M_Shop>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Manager.Model.Admin.M_Shop model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Manager.Model.Admin.M_Shop();
                    if (dt.Rows[n]["ShopID"] != null && dt.Rows[n]["ShopID"].ToString() != "")
                    {
                        model.ShopID = int.Parse(dt.Rows[n]["ShopID"].ToString());
                    }
                    if (dt.Rows[n]["ShopName"] != null && dt.Rows[n]["ShopName"].ToString() != "")
                    {
                        model.ShopName = dt.Rows[n]["ShopName"].ToString();
                    }
                    if (dt.Rows[n]["ShopTypeID"] != null && dt.Rows[n]["ShopTypeID"].ToString() != "")
                    {
                        model.ShopTypeID = int.Parse(dt.Rows[n]["ShopTypeID"].ToString());
                    }
                    if (dt.Rows[n]["ShopImage"] != null && dt.Rows[n]["ShopImage"].ToString() != "")
                    {
                        model.ShopImage = dt.Rows[n]["ShopImage"].ToString();
                    }
                    if (dt.Rows[n]["IsValid"] != null && dt.Rows[n]["IsValid"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsValid"].ToString() == "1") || (dt.Rows[n]["IsValid"].ToString().ToLower() == "true"))
                        {
                            model.IsValid = true;
                        }
                        else
                        {
                            model.IsValid = false;
                        }
                    }
                    if (dt.Rows[n]["ShopImage1"] != null && dt.Rows[n]["ShopImage1"].ToString() != "")
                    {
                        model.ShopImage1 = dt.Rows[n]["ShopImage1"].ToString();
                    }
                    if (dt.Rows[n]["ShopAddress"] != null && dt.Rows[n]["ShopAddress"].ToString() != "")
                    {
                        model.ShopAddress = dt.Rows[n]["ShopAddress"].ToString();
                    }
                    if (dt.Rows[n]["ShopTel"] != null && dt.Rows[n]["ShopTel"].ToString() != "")
                    {
                        model.ShopTel = dt.Rows[n]["ShopTel"].ToString();
                    }
                    if (dt.Rows[n]["ShopDesc"] != null && dt.Rows[n]["ShopDesc"].ToString() != "")
                    {
                        model.ShopDesc = dt.Rows[n]["ShopDesc"].ToString();
                    }
                    if (dt.Rows[n]["IsTop"] != null && dt.Rows[n]["IsTop"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsTop"].ToString() == "1") || (dt.Rows[n]["IsTop"].ToString().ToLower() == "true"))
                        {
                            model.IsTop = true;
                        }
                        else
                        {
                            model.IsTop = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

